/**
 * 项目名称：MSH
 * 包名称：com.mt.common.sys.dao
 * 文件名称：FunctionDaoImpl.java
 */
package com.mt.system.daoImpl;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;


import org.springframework.stereotype.Repository;

import com.mt.system.dao.FunctionDao;
import com.mt.system.domain.Funct;


/**
 * 类名称：FunctionDaoImpl <br>
 * 类描述： <br>
 * 创建人： 马腾 <br>
 * 创建时间：Oct 18, 2012 1:57:23 PM <br>
 */
@Repository
public class FunctionDaoImpl implements FunctionDao {
	
	@PersistenceContext
	private EntityManager entityManager;

	@Override
	public Funct addFunction(Funct funct) {
		entityManager.persist(funct);
		return funct;
	}

	@Override
	public void updateFunction(Funct funct) {
		entityManager.merge(funct);
	}

	@Override
	public void deleteFunction(Funct funct) {
		entityManager.remove(funct);
	}

	@Override
	public Funct getFunctionByName(String name) {
		String eql = "FROM Funct f WHERE f.name = :name";
		Query query = entityManager.createQuery(eql);
		query.setParameter("name", name);
		return (Funct) query.getSingleResult();
	}
}
